package com.wlcorp.forcazamis.sys.util;

@SuppressWarnings("unchecked")
public class LiteralType {

    public LiteralType() {
        
    }
    public static Object exchangeObjectType(Class propertyType, Object propertyValue) {
        if (propertyType == java.lang.String.class) {
            propertyValue = String.valueOf(propertyValue);
        }
        if (propertyType == java.lang.Long.class) {
            propertyValue = (Long)propertyValue;
        }
        if (propertyType == java.sql.Date.class) {
            propertyValue = DateUtil.stringToSqlDate(String.valueOf(propertyValue));
        }
        if (propertyType == java.util.Date.class) {
            propertyValue = DateUtil.stringToUtilDate(String.valueOf(propertyValue));
        }
        if (propertyType == java.lang.Integer.class) {
            String validPropertyValue = converToValidData(propertyValue);
            propertyValue = new Integer(validPropertyValue);
        }
        if (propertyType == java.lang.Float.class) {
            String validPropertyValue = converToValidData(propertyValue);
            propertyValue = Float.valueOf(validPropertyValue);
        }
        if (propertyType == java.lang.Double.class) {
            String validPropertyValue = converToValidData(propertyValue);
            propertyValue = Double.valueOf(validPropertyValue);
        }
        if (propertyType == java.lang.Boolean.class) {
            propertyValue = (Boolean)propertyValue;
        }
        if (propertyType == int.class ){
            String validPropertyValue = converToValidData(propertyValue);
            propertyValue = new Integer(validPropertyValue);
        }
        if (propertyType == float.class ){
            String validPropertyValue = converToValidData(propertyValue);
            propertyValue = new Float(validPropertyValue);
        }
        return propertyValue;
    }

    private static String converToValidData(Object propertyValue) {
        String validPropertyValue = String.valueOf(propertyValue);
        validPropertyValue = ExtendVoid.replace(validPropertyValue,"'","");
        if (ExtendVoid.isNumeric(validPropertyValue)){
            return validPropertyValue;
        }else{
            return "0";
        }
    }
}
